package com.lhys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lhys.mapper.AssetDiscardModeMapper;
import com.lhys.pojo.AssetDiscardMode;
import com.lhys.service.AssetDiscardModeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/*
 * <p>
 * 资产_报废方式表 服务实现类
 * </p>
 *
 * @author 小七
 * @since 2021-05-06
 */


@Service
public class AssetDiscardModeServiceImpl implements AssetDiscardModeService {
    @Autowired
    private AssetDiscardModeMapper assetDiscardModeMapper;

    @Override
    @Transactional
    public Boolean saveAssetDiscardMode(AssetDiscardMode assetDiscardMode) {
        try {
            if (assetDiscardMode.getId() == null) {
                assetDiscardMode.setCreateTime(new Date());
                return assetDiscardModeMapper.addAssetDiscardMode(assetDiscardMode) > 0;
            }
            return assetDiscardModeMapper.updateAssetDiscardMode(assetDiscardMode) > 0;
        } catch (Exception e) {
            System.out.println("重复添加");
            return null;
        }
    }

    @Override
    @Transactional
    public Boolean delAssetDiscardModeById(Integer id) {
        return assetDiscardModeMapper.delAssetDiscardMode(id) > 0;
    }

    @Override
    public AssetDiscardMode getAssetDiscardModeById(Integer id) {
        return assetDiscardModeMapper.getAssetDiscardModeById(id);
    }

    @Override
    public PageInfo<AssetDiscardMode> getAssetDiscardModeList(AssetDiscardMode assetDiscardMode , Integer pageNum , Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<AssetDiscardMode> list = assetDiscardModeMapper.getAssetDiscardModeByCodeAndTitleOrRemarkList(assetDiscardMode);
        PageInfo<AssetDiscardMode> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
